package com.sc.nft.admin.controller;


import cn.hutool.core.bean.BeanUtil;
import com.sc.nft.admin.request.*;
import com.sc.nft.annotation.SysMemberLogin;
import com.sc.nft.annotation.UserLogin;
import com.sc.nft.entity.EcologyHatchConf;
import com.sc.nft.entity.vo.EcologyHatchCountVO;
import com.sc.nft.entity.vo.EcologyHatchMetaMapVO;
import com.sc.nft.entity.vo.SelectDataByTimeVO;
import com.sc.nft.entity.vo.ecology.*;
import com.sc.nft.service.AdminEcologyHatchConfService;
import com.sc.nft.sup.PageResult;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jdk.nashorn.internal.ir.annotations.Ignore;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/admin/ecology/smelting")
@Api(tags = "后台生态熔炼配置管理")
public class AdminEcologySmeltingConfController {


    private final AdminEcologyHatchConfService adminEcologyHatchConfService;

    @PostMapping(value = "addAndUpdateSmeltingConf", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "新增或者修改生态熔炼配置", notes = "新增生态熔炼配置", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result addSmeltingConf(@Valid @RequestBody AddSmeltingConfRequest request) {
        EcologyHatchConf ecologyHatchConf = BeanUtil.copyProperties(request, EcologyHatchConf.class);
        adminEcologyHatchConfService.addSmeltingConf(ecologyHatchConf);
        return Result.success();
    }

    @PostMapping(value = "/getSmeltingPage", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "获取熔炼配置列表", notes = "获取熔炼配置列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<AdminSmeltingPageVO> getSmeltingPage(@Valid @RequestBody GetSmeltingPageRequest request) {
        return PageResult.success(adminEcologyHatchConfService.getSmeltingPage(request.getCollectionName(), request.getPageNo(), request.getPageSize()));
    }

    @PostMapping(value = "/getSmeltingDetails", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "获取熔炼配置详情", notes = "获取熔炼配置详情", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<AdminSmeltingDetailsVO> getSmeltingDetails(@Valid @RequestBody IdRequest request) {
        return Result.success(adminEcologyHatchConfService.getSmeltingDetails(request.getId()));
    }


    @PostMapping(value = "/delRewardsById", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "删除熔炼奖励配置", notes = "删除熔炼奖励配置", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result delRewardsById(@Valid @RequestBody IdRequest request) {
        adminEcologyHatchConfService.delRewardsById(request.getId());
        return Result.success();
    }

    @PostMapping(value = "/delConfById", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "删除熔炼配置", notes = "删除熔炼配置", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result delConfById(@Valid @RequestBody IdRequest request) {
        adminEcologyHatchConfService.delConfById(request.getId());
        return Result.success();
    }

    @PostMapping(value = "/updateSmeltinStatusgById", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "获取熔炼配置上下架", notes = "获取熔炼配置上下架", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result updateSmeltinStatusgById(@Valid @RequestBody StatusRequest request) {
        adminEcologyHatchConfService.updateSmeltinStatusgById(request.getId(), request.getStatus());
        return Result.success();
    }

    @PostMapping(value = "/updateSmeltingSortById", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "获取熔炼配置上下架", notes = "获取熔炼配置上下架", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result updateSmeltingSortById(@Valid @RequestBody SortRequest request) {
        adminEcologyHatchConfService.updateSmeltingSortById(request.getId(), Long.valueOf(request.getSort()));
        return Result.success();
    }

    @PostMapping(value = "/getSmeltingImage", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "获取生态熔炼配置图片", notes = "获取生态熔炼配置图片", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<List<AdminSmeltingImageVO>> getSmeltingImage() {
        return Result.success(adminEcologyHatchConfService.getSmeltingImage());
    }

    @PostMapping(value = "/updateSmeltingImage", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "修改生态熔炼配置图片", notes = "获取生态熔炼配置图片", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result updateSmeltingImage(@Valid @RequestBody UpdateSmeltingImageRequest request) {
        adminEcologyHatchConfService.updateSmeltingImage(request.getType(), request.getImage());
        return Result.success();
    }

    @PostMapping(value = "/selectDataByTime", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "根据时间查询汇总数据", notes = "根据时间查询汇总数据", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<SelectDataByTimeVO> selectDataByTime(@Valid @RequestBody SelectDataByTimeRequest request) {
        return Result.success(adminEcologyHatchConfService.selectDataByTime(request.getStartTime(), request.getEndTime()));
    }

    @PostMapping(value = "/userRecords", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "用户熔炼记录列表", notes = "用户熔炼记录列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<AdminMetaUserEcologyHatchRcordsVO> userRecords(@Valid @RequestBody UserEcologyHatchRcordsReuqest request) {
        return PageResult.success(adminEcologyHatchConfService.adminUserRecords(request.getCollectionName(), request.getUserTel(), request.getStartTime(), request.getEndTime(), request.getPageNo(), request.getPageSize(), request.getMethodName()));
    }

    @PostMapping(value = "/userRecordsDetails", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "用户熔炼记录详情", notes = "用户熔炼记录详情", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<List<AdminUserEcologyHatchRcordsDetailsVO>> userRecordsDetails(@Valid @RequestBody IdRequest request) {
        return Result.success(adminEcologyHatchConfService.userRecordsDetails(request.getId()));
    }

    @PostMapping(value = "/userEcologyCollectionRecords", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "熔炼详情消耗藏品记录", notes = "熔炼详情消耗藏品记录", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<List<UserEcologyCollectionRecordsVO>> userEcologyCollectionRecords(@Valid @RequestBody IdRequest request) {
        return Result.success(adminEcologyHatchConfService.userEcologyCollectionRecords(request.getId()));
    }

    @PostMapping(value = "/userRecordsExport", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "用户熔炼记录列表导出", notes = "用户熔炼记录列表导出", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    @Ignore
    public Result<List<AdminUserEcologyHatchRcordsVO>> userRecordsExport(@RequestBody UserEcologyHatchRecordsExportRequest request) {
        return Result.success(adminEcologyHatchConfService.userRecordsExport(null, request.getCollectionName(), request.getUserTel(), request.getStartTime(), request.getEndTime()));
    }

    @PostMapping(value = "/getPageUserRecordsRecords", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "用户熔炼记录奖励", notes = "用户熔炼记录奖励", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<AdminPageUserRewardsRecordsVO> getPageUserRecordsRecords(@Valid @RequestBody AdminPageUserRecordsRecordsRequest request) {
        return PageResult.success(adminEcologyHatchConfService.getPageUserRecordsRecords(request.getId(), request.getStartTime(), request.getEndTime(), request.getPageNo(), request.getPageSize()));
    }

    @ApiOperation(value = "获取熔炼剩余份数", notes = "获取熔炼剩余份数", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/findEcologyHatchCount", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin
    public Result<EcologyHatchCountVO> findEcologyHatchCount(@Valid @RequestBody EcologyHatchRequest request) {
        return PageResult.success(adminEcologyHatchConfService.findEcologyHatchCount(request.getEcologyHatchId()));
    }
}
